import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';

import {DataInterceptor} from "./libs/interceptors/data.interceptor"
import { HttpExceptionFilter} from "./libs/filters/http-exception.filter"
import {ValidationPipe} from "./libs/pipes/params-validation.pipe"
async function bootstrap() {
  const app = await NestFactory.create(AppModule);

  const config = new DocumentBuilder()
    .setTitle('Cats example')
    .setDescription('The cats API description')
    .setVersion('1.0')
    .addBearerAuth()
    .build();
  const document = SwaggerModule.createDocument(app, config);

  SwaggerModule.setup('api', app, document);

  // 规定统一正确的格式
  app.useGlobalInterceptors(new DataInterceptor());

  // 规定错误异常的响应格式
  app.useGlobalFilters(new HttpExceptionFilter());
  
  // 参数验证
  app.useGlobalPipes(new ValidationPipe());
  await app.listen(3000);
}
bootstrap();
